package com.kc.business.mapper;

import com.kc.business.domain.BizRole;
import com.kc.common.core.dao.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * FileName: BizRoleMapper
 * Author:   TP
 * Date:     2020-10-30 20:55
 * Description:
 */
public interface BizRoleMapper extends BaseMapper<BizRole> {

    /**
     * 获取角色列表
     *
     * @param bizRole 角色信息
     * @return 角色列表
     */
    List<BizRole> getList(BizRole bizRole);

    /**
     * 根据角色姓名查询角色信息
     *
     * @param roleName 角色姓名
     * @return 角色信息
     */
    @Select(value = "select * from kc_role where role_name = #{roleName} and is_deleted = 0")
    BizRole getActiveByRoleName(String roleName);

    /**
     * 根据角色标识查询角色信息
     *
     * @param roleKey 角色标识
     * @return 角色信息
     */
    @Select(value = "select * from kc_role where role_key = #{roleKey} and is_deleted = 0")
    BizRole getActiveByRoleKey(String roleKey);

    /**
     * 新增角色
     *
     * @param role 角色信息
     * @return 新增后的主键
     */
    int save(BizRole role);

    /**
     * 删除角色信息
     *
     * @param id 角色ID
     * @return 影响行数
     */
    @Update(value = "update kc_role set is_deleted = 1, update_by =#{username}, update_time = now() where id = #{id} ")
    int deleteById(@Param("id") Integer id,
                   @Param("username") String username);
}
